package controller.permission;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.Permission;
import service.PermissionService;
import service.impl.PermissionServiceImpl;
import utils.AJAXResult;
import utils.ResponseBodyUtil;


public class Update extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private PermissionService permissionService = new PermissionServiceImpl();
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		AJAXResult result = new AJAXResult();
		
		Permission permission = new Permission();
		permission.setName(request.getParameter("name"));
		permission.setUrl(request.getParameter("url"));
		permission.setId(Integer.parseInt(request.getParameter("id")));
				
		try {
			permissionService.updatePermission(permission);
			result.setSuccess(true);
		} catch ( Exception e ) {
			e.printStackTrace();
			result.setSuccess(false);
		}
		
		ResponseBodyUtil.sendJsonObject(response, result);
	}

}
